import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
} from '@nestjs/common';
import { BianhuantuService } from './bianhuantu.service';
import { CreateBianhuantuDto } from './dto/create-bianhuantu.dto';
import { UpdateBianhuantuDto } from './dto/update-bianhuantu.dto';
import { PagesDto } from '../dto/pages.dto';
import { BianhuantuEntity } from './entities/bianhuantu.entity';

@Controller('/admin/bianhuantu')
export class BianhuantuController {
  constructor(private readonly bianhuantuService: BianhuantuService) {}

  @Post()
  create(@Body() createBianhuantuDto: CreateBianhuantuDto) {
    return this.bianhuantuService.create(createBianhuantuDto);
  }
  @Post('/page')
  findAllPage(@Body() pages: PagesDto) {
    return this.bianhuantuService.findAllPage(pages);
  }
  @Post('/deleteList')
  deleteList(@Body() data: { list: BianhuantuEntity[] }) {
    return this.bianhuantuService.batchRemove(data.list.map((item) => item.id));
  }

  @Get()
  findAll() {
    return this.bianhuantuService.findAll();
  }

  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.bianhuantuService.findOne(+id);
  }

  @Patch(':id')
  update(
    @Param('id') id: string,
    @Body() updateBianhuantuDto: UpdateBianhuantuDto,
  ) {
    return this.bianhuantuService.update(+id, updateBianhuantuDto);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.bianhuantuService.remove(+id);
  }
}
